package dao;

import entity.User;
import org.apache.commons.dbutils.BasicRowProcessor;
import org.apache.commons.dbutils.GenerousBeanProcessor;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import utils.DataSourceUtils;

import java.nio.file.attribute.UserPrincipal;
import java.sql.SQLException;

public class LoginDao {
    public User selectByUsernameAndPassword(String username, String password) throws SQLException {
        QueryRunner queryRunner = new QueryRunner();
        //格式化数据库下划线
        GenerousBeanProcessor generousBeanProcessor = new GenerousBeanProcessor();
        BasicRowProcessor basicRowProcessor = new BasicRowProcessor(generousBeanProcessor);
        String sql = "select * from kfm_user where username = ? and password = ?";
        return queryRunner.query(DataSourceUtils.getConnection(), sql, new BeanHandler<>(User.class,basicRowProcessor), username, password);
    }

}

